home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7244 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  932 b 

  1. Path: tech.cftnet.com!not-for-mail
  2. From: wcowley@cftnet.com (Wes Cowley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Any way to restrict casting?
  5. Date: 22 Feb 1996 11:19:30 GMT
  6. Organization: CFTnet
  7. Message-ID: <4ghjg2$1po@tech.cftnet.com>
  8. References: <4gfuj4$1cu@news.mistral.co.uk>
  9. NNTP-Posting-Host: ppp244_8.cftnet.com
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Alan Campbell (alanc@mistral.co.uk) wrote:
  13. : Using Borland C++ 3.1, I find I can coerce a pointer to an instance of
  14. : a class into a pointer to *anything*.  Like an int.  
  15. :
  16. : [ code cut ]
  17. : Is this valid in all dialects of C++?  Is it part of the standard?  If
  18. : so, ouch.  
  19.  
  20. It's valid.  If you use a cast you're telling the compiler that you're 
  21. taking responsibility for the type system violation.  If you cast to 
  22. something that doesn't make sense, the compiler's not going to stop you
  23. because you've told it, via the cast, that you know what you're doing.
  24.  
  25. Wes
  26.